extends StateBase

var player: Player

func on_enter(owner = null, params = null):
	player = owner as Player
	
	var config = player.player_data.hold_item_data.item_config as MeleeWeaponConfig
	player.start_item_cooldown_timer(config.item_use_cooldown_time)
	
	if player.get_attack_charge_rate() > 0.5:
		AudioManager.play_sound("sfx_charge_release")
	player.attack_hand()
	player.current_hold_item_view.attack()
	
	var dash_velocity = config.dash_velocity
	player.velocity.x = dash_velocity * player.get_face()
	
	await get_tree().create_timer(0.1).timeout
	player.hold_hand()
	player.current_hold_item_view.stop_attack()
	
	player.states.transition("Move")
	

func on_exit(owner = null):
	player.velocity.x = 0
	if player.get_attack_charge_rate() > 0:
		player.create_charge_release_particle_effect()


func on_process(delta: float, owner = null):
	pass
	
	
func on_physics_process(delta: float, owner = null):
	player.process_gravity(delta)
	player.process_vertical_move_viewroot(delta)
	player.process_pickup()
	
	player.move_and_slide()
	
